# 编译阶段：用 Alpine 镜像编译 Go 代码
FROM golang:alpine AS builder
WORKDIR /app
ENV GOPROXY=https://goproxy.cn,direct
COPY go.mod ./
RUN go mod download
COPY . .
RUN go build -o app main.go  # 编译生成可执行文件 app

# 运行阶段：用极小 Alpine 镜像运行
FROM alpine:latest
WORKDIR /root/
COPY --from=builder /app/app .
COPY templates /root/templates
EXPOSE 8080
CMD ["./app"]